# 根据配置文件在前面控制器启动之后完成对交换机的基础配置
import subprocess
import logging
logger = logging.getLogger(None)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

def program_switch_cli(sw_name,thrift_port, command_txt):
        cli = 'simple_switch_CLI'
        # get the port for this particular switch's thrift server

        logging.info('Configuring switch %s with file %s' % (sw_name, command_txt))
        with open(command_txt, 'r') as fin:
            cli_outfile = '%s/%s_cli_output.log'%("logs", sw_name)
            with open(cli_outfile, 'w') as fout:
                subprocess.Popen([cli, '--thrift-port', str(thrift_port)],
                                 stdin=fin, stdout=fout)
                




